package com.lcredu.lcrliving.commodity.web;

import com.lcredu.lcrliving.commodity.entity.CategoryEntity;
import com.lcredu.lcrliving.commodity.service.CategoryService;
import com.lcredu.lcrliving.commodity.vo.Catalog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author kirito
 * @create 2023-12-12 13:43
 */
@Controller
public class IndexController {
    //装配categoryService
    @Resource
    private CategoryService categoryService;

    //响应用户请求首页
    @GetMapping(value = {"/", "/index.html"})
    private String indexPage(Model model) {
        //获取一级分类
        List<CategoryEntity> categories = categoryService.getLevel1Categories();

        //放入model
        model.addAttribute("categories",categories);

        System.out.println("level1Categories--->" + categories);
        //默认类路径中包含templates
        return "index";
    }

    //测试
    @GetMapping("/index/catalog.json")
    @ResponseBody
    public Map<String,List<Catalog2Vo>> getCataLogJson(){
        Map<String, List<Catalog2Vo>> cataLogJson = categoryService.getCataLogJson();
        return cataLogJson;
    }
}
